<?php

header('Content-Type:application/json');

@$kw = $_REQUEST['kw'];
$output = [];

if(empty($kw)){
    echo '';
    return;
}

$conn = mysqli_connect('127.0.0.1','root','','fruit');
$sql = "SET NAMES UTF8";
mysqli_query($conn,$sql);

$sql = "SELECT did,price,name,img_sm,detail FROM fruit_dish WHERE name LIKE '%$kw%' OR detail LIKE '%$kw%'";

$result = mysqli_query($conn,$sql);
while(true){
    $row = mysqli_fetch_assoc($result);

    if(!$row){break;}
    $output[] = $row;
}

echo json_encode($output);


?>